package com.scott.distrubutelock.javaapi;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

import java.util.concurrent.CountDownLatch;

/**
 * @author Scott 2017/11/2 18:30
 */
public class LockWatcher implements Watcher{

    private CountDownLatch countDownLatch;

    public LockWatcher(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void process(WatchedEvent event) {
        if(event.getType()==Event.EventType.NodeDeleted){
            countDownLatch.countDown();
        }
    }
}
